﻿namespace Anley.DomainDrivenDesign.Contract.Extension;

/// <summary>
/// 字节扩展类
/// </summary>
public static class ByteExtensions
{
    /// <summary>
    /// 转16进制字符串
    /// </summary>
    /// <param name="bytes"></param>
    public static string BytesToHexString(
        this byte[] bytes,
        bool toLower = true)
    {
        if (bytes == null || bytes.Length == 0)
            throw new ArgumentNullException(nameof(bytes));
        return string.Concat(bytes.Select(b => b.ToString(toLower == true ? "x2" : "X2")));
    }
}